package com.atguigu.tingshu.user.strategy.impl;
import java.util.Date;

import com.atguigu.tingshu.user.mapper.UserPaidAlbumMapper;
import com.google.common.collect.Maps;

import com.atguigu.tingshu.common.constant.SystemConstant;
import com.atguigu.tingshu.model.user.UserPaidAlbum;
import com.atguigu.tingshu.user.strategy.SaveUserPaidRecordStrategy;
import com.atguigu.tingshu.vo.user.UserPaidRecordVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 专辑购买，保存购买信息的策略实现类
 */
@Service
@Slf4j
public class UserPaidAlbumStrategy implements SaveUserPaidRecordStrategy {

    @Autowired
    private UserPaidAlbumMapper userPaidAlbumMapper ;

    /**
     * 需要考虑该接口的幂等性，就是给orderNo字段添加一个唯一约束
     * @param userPaidRecordVo
     */
    @Override
    public void saveUserPaidRecord(UserPaidRecordVo userPaidRecordVo) {

        String orderNo = userPaidRecordVo.getOrderNo();
        Long userId = userPaidRecordVo.getUserId();
        Long albumId = userPaidRecordVo.getItemIdList().get(0);

        // 创建一个UserPaidAlbum对象，封装要保存的数据
        UserPaidAlbum userPaidAlbum = new UserPaidAlbum() ;
        userPaidAlbum.setOrderNo(orderNo);
        userPaidAlbum.setUserId(userId);
        userPaidAlbum.setAlbumId(albumId);
        userPaidAlbumMapper.insert(userPaidAlbum) ;

    }

    @Override
    public String getItemType() {
        return SystemConstant.ORDER_ITEM_TYPE_ALBUM;
    }
}
